<template>
	<div></div>
</template>

<script setup lang="ts">
import { ref, reactive, toRefs, onMounted } from 'vue';
const response = await axios.post(
	'http://127.0.0.1:8000/tts',
	{
		text: inputText.value
	},
	{ responseType: 'blob' }
); // 验证响应的 Content-Type 是否为 audio/wav

const contentType = response.headers['content-type'];
console.log(contentType);
if (contentType !== 'audio/wav') {
	console.error('返回的不是有效的 WAV 文件');
	return;
} // 将二进制数据转换为 Blob 对象
//const blob = new Blob([new Uint8Array(response.data)], { type: 'audio/wav' });
const blob = new Blob([response.data], { type: 'audio/wav' }); // 创建一个 URL 对象来引用 Blob
const url = URL.createObjectURL(blob);
console.log(url); // 设置音频播放器的源

audioPlayer.value.src = url; // 播放音频
console.log('## will load audio'); //audioPlayer.value.load()
console.log('## will play audio');
await audioPlayer.value.play();
console.log('## play completed');
</script>
<style scoped lang="less"></style>
